#include "sceneObject.h"
#include <algorithm>

using namespace std;

SceneObject::SceneObject(){
	this->speed=0;
	this->kill=false;
}

SceneObject::SceneObject(float x1,float x2,float y1,float y2)
	:	dimensions(x1,x2,y1,y2){
	this->speed=0;
	this->kill=false;
}

SceneObject::SceneObject(Rectangle rec)
	:	dimensions(rec){
	this->speed=0;
	this->kill=false;
}

SceneObject::~SceneObject(){
	for (map<std::string,SceneObject*>::iterator it=listObject.begin();it!=listObject.end();++it)
		delete(it->second);
}

void SceneObject::addObject(const std::string& name,SceneObject* obj){
	listObject.insert( std::make_pair(name,obj) );
}

void SceneObject::removeObject(const std::string& name){
	map<std::string,SceneObject*>::iterator it= listObject.find(name);
	if (it==listObject.end())
		return;
	delete (it->second);
	listObject.erase(it);
}

SceneObject& SceneObject::findObject(const std::string& name)const{
	return *listObject.find(name)->second;
}

SceneObject* SceneObject::getObject(const std::string& name){
	map<std::string,SceneObject*>::iterator it= listObject.find(name);
	if (it==listObject.end())
		return NULL;
	SceneObject* ret = (it->second);
	listObject.erase(it);
	return ret;
}

void SceneObject::setDimensions(float x1,float x2,float y1,float y2){
	this->dimensions.set(x1,x2,y1,y2);
}
